package com.huakang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huakang.entity.Account;
import com.huakang.service.AccountService;
import com.huakang.utils.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author{小熊}
 * @Date2025/1/12 22:27
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @GetMapping("/getAll")
    public ResultVo getAll(@RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "3")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Account> list = accountService .getAll();
        PageInfo<Account> pageInfo = new PageInfo<>(list);
        return ResultVo.success("查询成功",pageInfo);
    }

    @PutMapping("/reset")
    public ResultVo reset(Integer aid){
       boolean flag =  accountService.reset(aid);
       if(flag){
           return ResultVo.success("重置密码成功");
       }
       return ResultVo.fail("重置密码失败");
    }
    @PutMapping("/updateStatus")
    public ResultVo updateStatus(Integer aid){
        boolean flag = accountService.updateStatus(aid);
        if(flag){
            return ResultVo.success("状态修改成功");
        }
        return ResultVo.fail("状态修改失败");
    }
}
